package com.xkdx.caipiao.presistence.findpsw;

import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.xkdx.caipiao.R;
import com.xkdx.caipiao.ThreadActivity;
import com.xkdx.caipiao.module.network.AbsModule;

public class FindPwsActivity extends ThreadActivity {

	EditText et_phoneOremail;
	Button next;

	public static String user_name;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.findpsw1_caipiao);
		et_phoneOremail = (EditText) findViewById(R.id.phoneOremail);
		next = (Button) findViewById(R.id.next);
		next.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				user_name = et_phoneOremail.getText().toString();
				if (!user_name.equals("") && isCellphone(user_name)) {
					Intent intent = new Intent(getApplicationContext(),
							FindPwsCodeActivity.class);
					startActivity(intent);
				} else {
					toast("请输入正确的邮箱或手机号");
				}

			}
		});
	}

	@Override
	public void showOnPost(HashMap<String, AbsModule> result) {

	}

	@Override
	public void startThread() {

	}

	@Override
	public void onBackClick(View view) {
		finish();

	}

	public static boolean isEmail(String strEmail) {
		String strPattern = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
		Pattern p = Pattern.compile(strPattern);
		Matcher m = p.matcher(strEmail);
		if (m.matches()) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean isCellphone(String str) {
		Pattern pattern = Pattern.compile("1[0-9]{10}");
		Matcher matcher = pattern.matcher(str);
		if (matcher.matches()) {
			return true;
		} else {
			return false;
		}
	}

}
